package crossrun.tool.pdf2img;

import android.widget.ScrollView;
import android.widget.TextView;

import java.text.SimpleDateFormat;
import java.util.Calendar;

public class TextLogUtil {

    private TextView logTxt;
    private ScrollView scrollView;
    private SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    public TextLogUtil(ScrollView scrollView,TextView logTxt) {
        this.logTxt = logTxt;
        this.scrollView = scrollView;
    }

    public void log(String msg){
        logTxt.append(msg);
        logTxt.append("\n");
        logTxt.append(dateFormat.format(Calendar.getInstance().getTime()));
        logTxt.append("\n");
        scrollView.post(new Runnable() {
            @Override
            public void run() {
                scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            }
        });
    }

    public void logln(String msg){
        logTxt.append(msg);
        logTxt.append("\n");
        logTxt.append(dateFormat.format(Calendar.getInstance().getTime()));
        logTxt.append("\n");
        logTxt.append("\n");
        scrollView.post(new Runnable() {
            @Override
            public void run() {
                scrollView.fullScroll(ScrollView.FOCUS_DOWN);
            }
        });
    }

    public void recycle(){
        scrollView=null;
        logTxt=null;
    }
}
